package com.vmladenov.cook.core.loaders;

import java.util.ArrayList;

import com.vmladenov.cook.core.db.IRepository;
import com.vmladenov.cook.core.html.SmallPreview;

public class IdLoader implements ISmallPreviewLoader
{
	protected final Integer pageSize = 10;
	protected long currentId = 0;
	protected long maxId = 0;
	private IRepository repository;

	public Boolean hasMore()
	{
		if (this.maxId == 0) maxId = getRepository().getMaxId();
		return currentId < this.maxId;
	}

	@Override
	public ArrayList<SmallPreview> getNextData()
	{
		long startId = currentId;
		ArrayList<SmallPreview> data = getRepository().getPreviews(startId);
		currentId = startId + pageSize;
		return data;
	}

	public void setRepository(IRepository repository)
	{
		this.repository = repository;
	}

	public IRepository getRepository()
	{
		return repository;
	}
}
